package com.spider.staticmethod;
//静态方法设计工具类
public class VerifyCodeUtil {
    public enum CodeType{
        NUMBER,//数字
        CHAR,//字母
        ALL//混合
    }
    public static void gerVerifyCode(int length,CodeType type){
        String chars;
        switch (type){
            case NUMBER:
                chars = "0123456789";
                break;
            case CHAR:
                chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
                break;
            default:
                chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
                break;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int index = (int)(Math.random() * chars.length());
            sb.append(chars.charAt(index));
        }
        System.out.println(sb.toString());
    }
}
